import json

json_res = json.dumps(True)
print(json_res,type(json_res))
#序列化
json_res = json.dumps([1, "ABC", True, (44, 55),"转换"])
print(json_res,type(json_res))
#反序列化
l = json.loads(json_res)
print(l,type(l))


#序列化输出到文件
with open("my.json",mode="wt",encoding="utf-8") as f:
    json.dump([1, "ABC", True, (44, 55),"转换"],f)

#从文件中反序列化
with open("my.json",mode="rt",encoding="utf-8") as f:
    l = json.load(f)
    print(l)

# 不是所有的Python对象都可以转换为JSON 如 set
# s = {1, 5, 8, 9}
# print(s,type(s))
# print(json.dumps(s))

bs = b'[1,3,"aa",[22,33]]'
print(bs,type(bs))
l = json.loads(bs)
print(l,type(l))



import pickle

s = pickle.dumps([1, "ABC", True, (44, 55),"转换"])
print(s,type(s))

l = pickle.loads(s)
print(l)
